package com.http;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;
import com.modle.UserResume;
import com.util.JsonUtil;

/**
 * 
 * @ClassName:UserResumeEditTask
 * @Description:TODO修改用户简历
 * @author zhuw
 * @date 2013-8-9 下午11:23:37
 */
public class UserResumeEditTask extends AsyncTask<HashMap<String ,Object>, Void, ResultUserResume> {
	public static interface CallBack extends NetWorkCallBack {
		/**
		 * 
		 * @Description:TODO处理底层获取后的数据
		 * @param result
		 * @return void
		 * @author zhuw
		 * @date 2013-4-24 上午10:19:30
		 */
		public abstract void procEditUserResumeData(UserResume data);

	}

	CallBack callback;

	public UserResumeEditTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultUserResume doInBackground(HashMap<String ,Object>... params) {
		ResultUserResume data = null;
		try {
			HashMap<String ,Object> map=params[0];
			String userid=(String)map.get("id");
			ArrayList<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
			if (map != null && !map.isEmpty()) {
				for (Map.Entry<String, Object> entry : map.entrySet()) {
					if(!entry.getKey().equals("id")){
						paramPairs.add(new BasicNameValuePair(entry.getKey(), entry
								.getValue().toString()));
					}
				}
			}
			ResEntity re=NetConUtil.postByForm(ServerPath.RESUME_EDIT_PATH+userid,paramPairs);
			if(re.code==ResEntity.S_OK){
			    data= new ResultUserResume(CommonData.H_FLAG_SUCCESS, null, JsonUtil.parseUserResume(new JSONArray(re.jsonStr).getJSONObject(0)));
			}else if(re.code==ResEntity.S_FAILED){
				
				  data= new ResultUserResume(CommonData.H_FLAG_ERROR, "code:"+re.code+"    "+re.jsonStr, null);
				
			}else{
				  data= new ResultUserResume(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
			}
			
		} catch (Exception e) {
			data= new ResultUserResume(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultUserResume result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procEditUserResumeData(result.data);

		} else {
			callback.procError(result.msg);
		}

	}
}
